package week_11;

import week_04.SingleList;

public class InsertionLikList {
    public static void sort(Comparable[] a) {
        SingleList<Integer> list = new SingleList<>();
//        把数组的数据放到链表中
        for (int l = 0; l < a.length; l++) {
            list.insert((Integer) a[l]);
        }
        for (int i=1;i<a.length;i++) {
            for (int j = i;j>0;j--) {
                if (greater(list.get(j-1),list.get(j))) {
                    list.perversion(j,j+1);
                } else {
                    break;
                }
            }
        }
        for (int l = 0; l < a.length; l++) {
            a[l] = list.get(l);
        }
    }

    public static boolean greater(Comparable v, Comparable w) {
        return v.compareTo(w) > 0;
    }
}
